// 实现这个项目的构建任务

const { src , dest, parallel, series} = require('gulp')
const sass = require('gulp-sass')
const babel = require('gulp-babel')
const swig = require('gulp-swig')
const imagemin = require('gulp-imagemin')
const del = require('del')
 
const data = {
    menus: [
      {
        name: 'Home',
        icon: 'aperture',
        link: 'index.html'
      },
      {
        name: 'Features',
        link: 'features.html'
      },
      {
        name: 'About',
        link: 'about.html'
      },
      {
        name: 'Contact',
        link: '#',
        children: [
          {
            name: 'Twitter',
            link: 'https://twitter.com/w_zce'
          },
          {
            name: 'About',
            link: 'https://weibo.com/zceme'
          },
          {
            name: 'divider'
          },
          {
            name: 'About',
            link: 'https://github.com/zce'
          }
        ]
      }
    ],
    pkg: require('./package.json'),
    date: new Date()
  }

const clean = () =>{
    return del(['dist'])
}

const style = () => {
    return src('src/assets/styles/*.scss',{ base:'src'})
            .pipe(sass())
            .pipe(dest('dist'))
}

const script = () => {
    return src('src/assets/scripts/*.js',{ base:'src'})
            .pipe(babel({ presets:['@babel/preset-env']}))
            .pipe(dest('dist'))
}
const page = () => {
    return src('src/**/*.html',{ base:'src'})
            .pipe(swig(data))
            .pipe(dest('dist'))
}

const image = () => {
    return src('src/assets/images/**',{ base:'src'})
            .pipe(imagemin())
            .pipe(dest('dist'))
}
const font = () => {
    return src('src/assets/fonts/**',{ base:'src'})
            .pipe(imagemin())
            .pipe(dest('dist'))
}

const extra = () => {
    return src('public/**',{ base:'public'})
            .pipe(dest('dist'))
}

const complie = parallel(style, script, page, image, font)

// 先进行清除，在进行编译

const build =  series(clean,parallel(complie, extra))
module.exports = {
//  style,
//  script,
//  page,
// font,
// image,
complie,
build
}
